package com.project.easy.common.framework.generator.config;

import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.project.easyt.common.db.common.config.WriteDbConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author GreatorMan.cool
 * @copyright: Copyright (c) 2020
 * @company: 扬起科技有限公司
 * @date 2021/10/3 22:00
 * @description: 配置开启代码模板生成配置
 */
@Configuration
@ConditionalOnProperty(prefix = "yqkj.zysoft.generator", name = "enable", havingValue = "true", matchIfMissing = true)
public class YqkjZysoftGeneratorConfig {

    @Autowired
    private WriteDbConfig readDbConfig;

    /**
     * 获取模板生成器配置
     * @return 返回配置对象
     */
    @Bean
    @ConditionalOnMissingBean(DataSourceConfig.class)
    public DataSourceConfig getDataSourceConfig() {
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl(this.readDbConfig.getUrl());
        dsc.setDriverName(this.readDbConfig.getDriverClass());
        dsc.setUsername(this.readDbConfig.getUsername());
        dsc.setPassword(this.readDbConfig.getPassword());
        return dsc;
    }
}
